package com.luoxiang.socialandroid.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.Window
import android.view.WindowManager
import androidx.recyclerview.widget.GridLayoutManager
import com.blankj.utilcode.util.ScreenUtils
import com.luoxiang.socialandroid.R
import com.luoxiang.socialandroid.adapter.IllustrateAdapter
import com.luoxiang.socialandroid.bean.IllustrateData
import com.luoxiang.socialandroid.bean.InvitesData
import com.luoxiang.socialandroid.bean.ListReward
import com.luoxiang.socialandroid.databinding.DialogListIllstrateBinding

/**
 * Author: fuxinbo

 * Date: 2023/2/10

 * Description:
 */
class ListIllustrateDialog @JvmOverloads constructor(
    context: Context,
    themeResId: Int = R.style.Dialog
) :
    Dialog(context, themeResId) {

    private var mAdapter: IllustrateAdapter? = null

    private var mAdapter2: IllustrateAdapter? = null

    private val binding: DialogListIllstrateBinding by lazy {
        DialogListIllstrateBinding.inflate(
            layoutInflater
        )
    }

    init {
        setContentView(binding.root)
        initDialog()
        initView()
    }

    fun setList(list: IllustrateData) {
        binding.textTitle1.text = list.invites.title
        binding.textTitle2.text = list.charms.title
        mAdapter?.setList(list.invites.list)
        mAdapter2?.setList(list.charms.list)
    }

    /**
     * 初始化弹窗属性
     *
     */
    private fun initDialog() {
        context.let {
            val dialogWindow: Window? = this.window
            dialogWindow?.setGravity(Gravity.CENTER)
            val lp: WindowManager.LayoutParams? = dialogWindow?.attributes
            lp?.height = WindowManager.LayoutParams.WRAP_CONTENT
            lp?.width = ScreenUtils.getScreenWidth() - (32 * 4)
            dialogWindow?.setAttributes(lp)
        }
    }

    private fun initView() {
        if (mAdapter == null) {
            mAdapter = IllustrateAdapter()
            mAdapter2 = IllustrateAdapter()
        }
        binding.recyclerReward.apply {
            adapter = mAdapter
            layoutManager = GridLayoutManager(context, 2)
            setHasFixedSize(true)
        }
        binding.recyclerReward2.apply {
            adapter = mAdapter2
            layoutManager = GridLayoutManager(context, 2)
            setHasFixedSize(true)
        }
        binding.buttonClose.setOnClickListener {
            hide()
        }
    }
}